package org.example.sdpback.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.sdpback.domain.entity.Project;
import org.example.sdpback.domain.entity.User;
import org.example.sdpback.mapper.ProjectMapper;
import org.example.sdpback.service.ProjectService;
import org.example.sdpback.utils.ThreadLocalUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {
    @Override
    public void addProject(Project project) {

        User user = ThreadLocalUtil.get();
        project.setUsername(user.getUsername());
        project.setCreateTime(LocalDateTime.now());
        project.setUpdateTime(LocalDateTime.now());
        save(project);
    }

    @Override
    public void updateProject(Project project) {
        project.setUpdateTime(LocalDateTime.now());
        updateById(project);
    }

    @Override
    public List<Project> getProjectList(String projectName, String userName) {
        return lambdaQuery().like(projectName != null && !projectName.equals(""), Project::getName, projectName)
                .eq(userName != null && !userName.equals(""), Project::getUsername, userName)
                .list();
    }

}
